<!-- 招聘主页/单位基本信息 -->
<template>
  <div class="editInfo">
    <div class="page flex-col">
      <div class="box_1 flex-row">
        <div class="banner">
          <!-- 头部 -->
          <el-header></el-header>
        </div>
        <div class="bgc">
          <div class="banner">
            <div class="box_2 flex-col">
              <div class="group_1 flex-row justify-between">
                <div class="box_2 flex-col">
                  <div class="box_3 flex-col">
                    <div class="text-wrapper_1 flex-col" @click="toenterprisePosition">
                      <img class="label_4" referrerpolicy="no-referrer"
                        src="../../assets/images/enterpriseIndex/zw.png" />
                      <span class="text_8">职位</span>
                    </div>
                    <div class="text-wrapper_2 flex-col">
                      <img class="thumbnail_2" referrerpolicy="no-referrer"
                        src="../../assets/images/enterpriseIndex/zpzyred.png" />
                      <span class="text_9">招聘主页</span>
                    </div>
                  </div>
                </div>

                <div class="box_4 flex-col">
                  <div class="text-wrapper_3 flex-col">
                    <span class="text_11">招聘主页/单位基本信息</span>
                  </div>
                  <div class="box">
                    <div class="line1">
                      <el-form class="demo-ruleForm">
                        <el-form-item label="单位全称" prop="name">
                          <p>{{ ruleForm.comp_name }}</p>
                          <div class="right">
                            <div>
                              单位对外展示名称如需更改，请联系客服（{{ tel }}）
                            </div>
                          </div>
                        </el-form-item>
                      </el-form>
                    </div>
                    <div class="line2">
                      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="demo-ruleForm">
                        <el-form-item label="营业执照统一代码" prop="comp_license">
                          <el-input v-model="ruleForm.comp_license" placeholder="请输入营业执照" maxlength="18"
                            minlength="18"></el-input>
                        </el-form-item>
                        <el-form-item label="单位注册地" prop="regis_address" class="zcd">
                          <el-cascader :options="options" :props="areaProps" v-model="ruleForm.regis_address"
                            placeholder="请选择地址"></el-cascader>
                        </el-form-item>
                        <el-form-item label="单位性质" prop="comp_type">
                          <el-select v-model="ruleForm.comp_type" placeholder="请选择">
                            <el-option :label="item.title" :value="item.nature_id" v-for="(item, index) in nature_list"
                              :key="index"></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="所属行业" prop="industry_id">
                          <el-select v-model="ruleForm.industry_id" placeholder="请选择">
                            <el-option :label="item.title" :value="item.industry_id"
                              v-for="(item, index) in industry_list" :key="index"></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="单位规模" prop="comp_worker">
                          <el-select v-model="ruleForm.comp_worker" placeholder="请选择">
                            <el-option :label="item.title" :value="item.scale_id" v-for="(item, index) in scale_list"
                              :key="index"></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="注册资金（/万）" prop="regis_money">
                          <el-input v-model="ruleForm.regis_money"></el-input>
                        </el-form-item>
                        <el-form-item label="融资阶段" prop="stage_id">
                          <el-select v-model="ruleForm.stage_id" placeholder="请选择">
                            <el-option :label="item.title" :value="item.stage_id" v-for="(item, index) in stage_list"
                              :key="index"></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="成立时间" prop="regis_time">
                          <el-date-picker type="date" placeholder="请选择成立时间" :picker-options="pickerOptions" v-model="ruleForm.regis_time"
                            value-format="yyyy-MM-dd" style="width: 100%"></el-date-picker>
                        </el-form-item>
                        <div class="line3">
                          <el-form-item label="企业logo" prop="logo" style="width: 100px; display: flex; flex-wrap: wrap">
                            <el-upload class="avatar-uploader" list-type="picture-card" name="img"
                              :action="this.upImgUrl" :on-success="handleAvatarSuccesslogo" :show-file-list="false"
                              :before-upload="beforeAvatarUpload">
                              <img v-if="ruleForm.logo_image" :src="ruleForm.logo_image" class="avatar">
                              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                            </el-upload>
                          </el-form-item>
                          <span
                            class="paragraph_1"><br />1.支持jpg、png、jpeg格式的图片，大小不超过2M；<br />2.尺寸不小于200*200px，正方形（1:1）效果最佳。</span>
                        </div>
                        <div class="line3">
                          <el-form class="demo-ruleForm" style="margin-top: 10px">
                            <el-form-item label="企业环境" prop="logo"></el-form-item>
                          </el-form>
                          <div class="dwhj">
                            <el-upload :action="this.upImgUrl" list-type="picture-card"
                              :on-preview="handlePictureCardPreview" name="img" :on-success="handleSuccessa"
                              :file-list="pdf_img_list" :on-remove="removeImg" :before-upload="beforeAvatarUpload">
                              <i class="el-icon-plus"></i>
                            </el-upload>
                            <el-dialog :visible.sync="dialogVisible" append-to-body>
                              <img width="100%" :src="dialogImageUrl" alt="" />
                            </el-dialog>
                            <span
                              class="paragraph_1"><br />1.支持jpg、png、jpeg格式的图片，大小不超过2M；<br />2.尺寸不小于200*200px，正方形（1:1）效果最佳。</span>
                          </div>
                        </div>
                        <div class="line3a">
                          <el-form class="demo-ruleForm" style="margin-top: 10px">
                            <el-form-item label="宣传视频" prop="video"></el-form-item>
                          </el-form>
                          <div>
                            <el-upload :action="this.upVideoUrl" list-type="picture-card" :file-list="videoFileList"
                              class="upload-demo" name="video_file" :on-success="handleSuccessv"
                              :before-upload="beforeAvatarUploadv" :on-preview="handlePictureCardPreviewv" :limit="1"
                              :on-exceed="handleExceedv" :on-remove="removevideo">
                              <i class="el-icon-plus"></i>
                            </el-upload>
                            <el-dialog title="视频预览" :visible.sync="videoDialogVisible" width="80%" append-to-body>
                              <video width="100%" controls>
                                <source :src="video_url" type="video/mp4" />
                              </video>
                            </el-dialog>
                          </div>
                        </div>
                        <div class="desc">
                          <el-form-item label="单位介绍" prop="comp_desc">
                            <el-input type="textarea" v-model="ruleForm.comp_desc" placeholder="请输入"
                              resize="none"></el-input>
                          </el-form-item>
                        </div>
                      </el-form>
                    </div>
                    <div class="btnred">
                      <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import elHeader from "../../common/elHeader.vue";
import { mapState } from "vuex";
import { upImgUrl, upVideoUrl } from "../../utils/baseUrl.js";
import { TRUE } from "sass";
import { regionData } from "element-china-area-data";
export default {
  data() {
    return {
      pickerOptions: {
                disabledDate(time) {
                    return time.getTime() > Date.now();
                },
            },
      disabled: false,
      imageUrl: "",
      input: "",
      ruleForm: {
        comp_license: "",
        logo_image: "",
        regis_money: "",
        regis_address: [],
        comp_desc: "",
        comp_worker: "",
        comp_type: "",
        industry_id: "",
        stage_id: "",
        regis_time: "",
        // envir_image: [],
        deshow: false,
        Afterdeshow: true,
      },
      rules: {
        comp_license: [{ required: true, message: "请填写统一信用代码", trigger: "change" }],
        regis_address: [
          { required: true, message: "请选择单位注册地", trigger: "change" },
        ],
        comp_type: [
          { required: true, message: "请选择单位性质", trigger: "change" },
        ],
        industry_id: [
          { required: true, message: "请选择所属行业", trigger: "change" },
        ],
        comp_worker: [
          { required: true, message: "请选择单位规模", trigger: "change" },
        ],
        regis_money: [{ required: true, message: "请填写注册资金", trigger: "blur" }],
        stage_id: [
          { required: true, message: "请选择融资阶段", trigger: "change" },
        ],
        regis_time: [
          { required: true, message: "请选择成立时间", trigger: "change" },
        ],
        comp_desc: [
          { required: true, message: "请填写", trigger: "blur" },
          { message: "字数超限，最多可输入300字", trigger: "blur" },
        ],
      },
      areaProps: {
        value: "label",
        label: "label",
      },
      industry_list: [],
      nature_list: [],
      scale_list: [],
      stage_list: [],
      envir_image: [],
      pdf_img_list: [
        {
          name: "",
          url: "",
          uid: "",
        },
      ],
      dialogImageUrl: "", //这个是放大展示弹框里的图片
      dialogVisible: false,
      upImgUrl: "",
      upVideoUrl: "",
      video_url: "",
      videoFileList: [
        // {
        //   url: '',
        // }
      ],
      videoDialogVisible: false,
      isVideo: false,
      isAdd: true,
      tel: "",
      options: regionData, //级联选择器
      selectedOptions: [],
    };
  },
  created() {
    this.upImgUrl = upImgUrl;
    this.upVideoUrl = upVideoUrl;

    const cachedDataStr = localStorage.getItem("zp_index_base");
    if (cachedDataStr) {
      const cachedData = JSON.parse(cachedDataStr);
      this.tel = cachedData.IndexBase.tel;
    }
  },
  computed: {
    ...mapState(["IndexBase"]),
    // tel() {
    //   return this.IndexBase ? this.IndexBase.tel : null;
    // },
    img_url1() {
      return this.pdf_img_list.map((item) => {
        return item.url;
      });
    },
    img_url2() {
      return this.videoFileList.map((item) => {
        return item.url;
      });
    },
  },
  mounted() {
    this.getInfo();
    this.getOtherInfo();
    if (!localStorage.getItem("methodExecuted")) {
      this.aa();
      localStorage.setItem("methodExecuted", "true");
    }
  },
  methods: {
    talentLibrary() {
      this.$router.push("/talentLibrary")
    },
    handleAvatarSuccesslogo(res, file, fileList) {
      console.log(res, "resresres");
      console.log(file, "filefilefile");
      console.log(fileList, "fileListfileListfileList");
      this.ruleForm.logo_image = res.info.img_url;
    },
    aa() {
      regionData.forEach((item) => {
        item.children.forEach((i2) => {
          i2.children.unshift({
            value: "",
            label: "不限",
            children: null,
          });
        });
      });
    },
    handleExceedv(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件`);
    },
    //控制上传数量提示
    handleExceed(files, fileList) {
      this.$message.warning(`最多上传1个图片`);
    },

    //查看大图
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    //查看大图
    handlePictureCardPreviewv(file) {
      this.video_url = file.url;
      this.videoDialogVisible = true;
    },
    async getInfo() {
      const res = await this.$service.get({
        url: "/api/zp/v1/zpapp_comp_info",
      });
      if (res.code == 1) {
        this.ruleForm = res.info;
        localStorage.setItem("comp_worker", res.info.comp_worker);
        this.envir_image = res.info.envir_image;
        this.video_url = res.info.promotional_video;
        this.ruleForm.regis_address = res.info.regis_address.split(",");

        this.pdf_img_list = this.envir_image.map((item) => {
          return {
            name: item.name,
            url: item,
          };
        });
        if (this.video_url) {
          this.isVideo = true;
          this.isAdd = true;
          this.videoFileList.push({ url: this.video_url });
        } else {
          this.isVideo = false;
          this.isAdd = true;
          // this.videoDialogVisible = false;
        }
      } else {
        this.$message.error(res.msg);
      }
    },
    async getOtherInfo() {
      const res = await this.$service.get({
        url: "/api/zp/v1/zpapp_stage_type",
      });
      console.log(res);
      this.industry_list = res.info.industry_list;
      this.nature_list = res.info.nature_list;
      this.scale_list = res.info.scale_list;
      this.stage_list = res.info.stage_list;
    },
    enterprisePosition() {
      this.$router.push("/enterprisePosition");
    },
    // 上传成功
    handleSuccessa(file, fileList) {
      console.log(file, "filefilefile");
      console.log(fileList, "fileListfileListfileList");
      this.envir_image = file.info.img_url;
      this.pdf_img_list.push({
        name: "",
        url: this.envir_image,
        uid: fileList.uid,
      });
    },
    handleSuccessv(file, fileList) {
      console.log(file, "file");
      fileList;
      console.log(fileList, "fileList");

      this.video_url = file.info.video_url;
      console.log(this.video_url, "vvvvvvvvvvvvvvvvvvvvvvvvvv");
      // this.videoDialogVisible = true;
    },
    // 移除图片
    removeImg(file, fileList) {
      console.log(file, fileList, "removeImg");
      this.pdf_img_list = fileList.map((item) => {
        return item.url;
      });
    },
    removevideo(file, fileList) {
      this.video_url = "";
    },
    beforeAvatarUpload(file) {
      const isJPGorPNG =
        file.type === "image/jpeg" || file.type === "image/png";
      const isLt5M = file.size / 1024 / 1024 < 5;
      if (!isJPGorPNG) {
        this.$message.error("请上传 JPG 或 PNG 格式的图片!!");
      }
      if (!isLt5M) {
        this.$message.error("上传头像图片大小不能超过 5MB!");
      }
      return isJPGorPNG && isLt5M;
    },
    beforeAvatarUploadv(file) {
      console.log("fileeeeeeeeee", file);
      const isVideo = file.type.startsWith("video/");
      const isLt500M = file.size / 1024 / 1024 < 500;

      if (!isVideo) {
        this.$message.error("请上传视频文件!!");
      }
      if (!isLt500M) {
        this.$message.error("上传视频大小不能超过 500MB!");
      }

      return isVideo && isLt500M;
    },
    // 保存
    submitForm(formName) {
      this.ruleForm.regis_address = this.ruleForm.regis_address.join(",");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.setInfo();
        } else {
          console.log("error submit!!");
          // this.$message.info('error submit!!', res.msg)
          return false;
        }
      });
    },
    setInfo() {
      console.log(this.ruleForm.regis_address);
      this.$service
        .post({
          url: "/api/zp/v1/zpapp_edit_comp_info",
          data: {
            ...this.ruleForm,
            envir_image: this.img_url1.join(","),
            promotional_video: this.video_url,
            regis_address: this.ruleForm.regis_address,
          },
        })
        .then((res) => {
          console.log(res, "");
          this.$message.info(res.msg);
          if (res.code == 1) {
            localStorage.setItem("is_finsh", 1);
            this.toenterprisePosition();
          } else {
            this.$message.info(res.msg);
          }
        });
    },
    toenterprisePosition(){
      this.$router.push("/enterprisePosition");
    }
  },
  components: {
    elHeader,
  },
};
</script>

<style scoped>
.btnred {
  display: flex;
  justify-content: center;
}

.bgc {
  background-color: rgba(242, 242, 242, 1);
  position: relative;
  padding: 20px 0 20px 0;
  box-sizing: border-box;
}

::v-deep .el-upload-list__thumb img {
  display: none !important;
  /* 隐藏图标 */
}

::v-deep .el-form-item__content {
  width: 350px;
}

.zcd {
  display: flex;
  flex-wrap: wrap;
}

.dwhj {
  display: flex;
}

::v-deep .zcd .el-input__inner {
  width: 350px;
}

.box_3 img.thumbnail_2 {
  background: rgb(252, 247, 247);
}

::v-deep .desc .el-textarea__inner {
  width: 786px !important;
  height: 218px;
  background: #ffffff;
  border-radius: 4px;
}

.desc {
  padding-top: 25px;
  box-sizing: border-box;
}

::v-deep .el-select .el-input__inner {
  width: 350px;
}

.el-form-item {
  width: 47%;
  padding-right: 20px;
  box-sizing: border-box;
}

* {
  list-style: none;
  background-color: transparent;
}

.page {
  background-color: rgba(242, 242, 242, 1);
  position: relative;
}

.box_1 {
  background-color: rgba(255, 255, 255, 1);
  height: 117px;
}

.banner {
  width: 1200px;
  margin: 0 auto;
}

.group_1 {
  width: 1204px;
  margin-top: 28px;
  display: flex;
  justify-content: space-between;
}

.box_3 {
  background-color: rgba(255, 255, 255, 1);
  width: 280px;
  height: 1207px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
}

.box_3 img {
  background-color: #fff;
}

.text_7 {
  width: 280px;
  height: 24px;
  overflow-wrap: break-word;
  color: rgba(0, 0, 0, 1);
  font-size: 20px;
  font-family: PingFangSC-Semibold;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  line-height: 24px;
  background: #fff;
  display: flex;
  justify-content: center;
  margin-top: 27px;
}

.text-wrapper_1 {
  height: 56px;
  background-color: #fff;
  width: 280px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.text_8 {
  width: 64px;
  height: 24px;
  overflow-wrap: break-word;
  color: rgba(0, 0, 0, 1);
  font-size: 16px;
  font-family: PingFangSC-Semibold;
  font-weight: 600;
  white-space: nowrap;
  line-height: 24px;
  margin-left: 26px;
  background-color: unset;
}

.text-wrapper_2 {
  height: 56px;
  background: rgb(252, 247, 247);
  background-size: 100% 100%;
  width: 280px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.text_9 {
  width: 64px;
  height: 24px;
  overflow-wrap: break-word;
  color: rgba(244, 0, 19, 1);
  font-size: 16px;
  font-family: PingFangSC-Semibold;
  font-weight: 600;
  white-space: nowrap;
  line-height: 24px;

  margin-left: 26px;
}

.box_4 {
  width: 892px;
  /* height: 1053px; */
}

.text-wrapper_3 {
  background-color: rgba(255, 255, 255, 1);
  height: 72px;
  width: 892px;
  display: flex;
}

.text_11 {
  width: 168px;
  height: 22px;
  overflow-wrap: break-word;
  color: rgba(18, 18, 18, 1);
  font-size: 16px;
  font-family: PingFangSC-Semibold;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  line-height: 22px;
  margin: 26px 0 0 30px;
}

.box {
  background-color: #fff;
  width: 892px;
  /* height: 1423px; */
  margin-top: 12px;
  padding: 32px 77px 20px 29px;
  box-sizing: border-box;
  position: relative;
}

.line1 {
  height: 50px;
  position: relative;
  margin-bottom: 37px;
}

.line1 p:nth-child(1) {
  font-size: 16px;
  font-family: PingFangSC, PingFang SC;
  font-weight: 600;
  color: #333333;
  line-height: 16px;
  position: absolute;
  top: 33px;
  left: 0px;
}

.el-form-item__label {
  line-height: normal;
  margin-bottom: 16px;
}

.group_4 {
  background-color: rgba(201, 226, 251, 1);
  width: 61px;
  height: 16px;
  display: flex;
  position: absolute;
  top: 33px;
  left: 114px;
}

.thumbnail_3 {
  width: 10px;
  height: 12px;
  margin: 2px 0 0 3px;
}

.text_16 {
  width: 42px;
  height: 14px;
  overflow-wrap: break-word;
  color: rgba(13, 79, 142, 1);
  font-size: 14px;
  font-family: PingFangSC-Regular;
  font-weight: normal;
  text-align: left;
  white-space: nowrap;
  line-height: 14px;
  margin: 1px 3px 0 0;
}

.line1 .right {
  width: 398px;
  height: 50px;
  display: flex;
  flex-wrap: wrap;
  align-content: space-between;
  font-size: 14px;
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  color: #999999;
  position: absolute;
  left: 430px;
}

.el-form-item__content {
  line-height: normal;
  height: 50px;
}

.line1 .right p {
  font-size: 16px;
  font-family: PingFangSC, PingFang SC;
  font-weight: 600;
  color: #333333;
  line-height: 16px;
}

.thumbnail_right {
  width: 8px;
  height: 12px;
  background-color: #fff;
  position: relative;
  top: -27px;
  left: 330px;
}

.line2 {
  /* height: 367px; */
  display: flex;
}

.el-input--prefix .el-input__inner {
  width: 348px;
  height: 36px;
}

.el-input__icon {
  display: none;
}

.el-input--prefix .el-input__inner {
  padding-left: 10px;
}

.line2 .demo-ruleForm {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.el-input__inner {
  width: 348px;
  height: 36px;
}

.el-form-item__error {
  top: 140%;
}

.thumbnail_right .right {
  color: red;
}

.thumbnail_r {
  width: 8px;
  height: 12px;
  background-color: #fff;
  position: relative;
  top: 0;
  left: -20px;
}

.line3 {
  /* height: 230px; */
  margin-top: 30px;
  position: relative;
  width: 100%;
}

.line3a {
  /* height: 230px; */
  margin-top: 30px;
  position: relative;
  width: 100%;
}

.line4 {
  margin-top: 50px;
}

.upload {
  width: 176px;
  height: 176px;
  background: #ffffff;
  border-radius: 4px;
  border: 1px solid #e5e5e5;
  position: relative;
  top: -18px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.upload p {
  width: 96px;
  height: 22px;
  overflow-wrap: break-word;
  color: rgba(0, 0, 0, 1);
  font-size: 16px;
  font-family: PingFangSC-Regular;
  font-weight: normal;
  text-align: left;
  white-space: nowrap;
  line-height: 22px;
  margin-top: 16px;
}

.avatar {
  width: 145px;
  height: 145px;
}

.paragraph_1 {
  display: inline-block;
  width: 410px;
  overflow-wrap: break-word;
  color: rgba(153, 153, 153, 1);
  font-size: 14px;
  font-family: PingFangSC-Regular;
  font-weight: normal;
  position: absolute;
  bottom: -42px;
  left: 0;
}

.el-textarea__inner {
  width: 786px;
  height: 229px;
  padding-top: 12px;
}

.box button {
  width: 239px;
  height: 48px;
  background: #d81d06;
  border-radius: 4px;
  /* position: absolute; */
  border: none;
  /* top: 1326px; */
  /* left: 327px; */
  font-size: 16px;
  font-family: PingFangSC, PingFang SC;
  font-weight: 600;
  color: #ffffff;
}

::v-deep .upload-demo .el-upload-list--picture-card .el-upload-list__item-thumbnail {
  width: 100%;
  height: 100%;
  background-image: url(../../assets/images/editInfo/hj.png) !important;
}

::v-deep .upload-demo .el-upload-list--picture-card .el-upload-list__item {
  overflow: hidden;
  background-image: url(../../assets/images/editInfo/hj.png) !important;
  border: 1px solid #c0ccda;
  border-radius: 6px;
  box-sizing: border-box;
  width: 148px;
  height: 148px;
  margin: 0 8px 8px 0;
  display: inline-block;
}

::v-deep .upload-demo .el-upload-list__item .el-upload-list__item-thumbnail {
  display: none;
}
</style>
